﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="frmCatalogarProducto.aspx.cs" Inherits="Box.Cliente.Ventas.frmCatalogarProducto" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="FeaturedContent" runat="server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="MainContent" runat="server">
    
    <script type="text/javascript">
        $(document).read(function () {
            $("#<%= txtTalla.ClientID %>").keypress(function () {
                if (Char.IsLetter(e.KeyChar)) {
                    e.Handled = false;
                }
                else if (Char.IsControl(e.KeyChar)) {
                    e.Handled = false;
                }
                else if (Char.IsSeparator(e.KeyChar)) {
                    e.Handled = false;
                }
                else {
                    e.Handled = true;
                }
            });
        });
    </script>

    <div class="panel panel-primary">
    	<div class="panel-heading">
    	    <h2>Catalogar Producto</h2>
    	</div>
    	<div class="panel-body">
    	    <table>
    	        <tr>
    	            <td><asp:TextBox runat="server" ID="txtCodigo" Visible="False"></asp:TextBox></td>
    	        </tr>
    	        <tr>
    	            <td><label>Nombre Producto</label></td>
    	            <td><asp:TextBox runat="server" ID="txtNombreProducto" MaxLength="50" CssClass="form-control input-sm"/>
                        <asp:RequiredFieldValidator ID="nombreValidate"  ControlToValidate="txtNombreProducto" ForeColor="Red" runat="server" Text="Debe ingresar uno nombre para el producto" ErrorMessage="RequiredFieldValidator"></asp:RequiredFieldValidator>
                    </td>
                    <td>
                        <label>Talla</label></td>
                    <td>
                        <asp:TextBox runat="server" CssClass="form-control input-sm" MaxLength="3" ID="txtTalla"></asp:TextBox>
                    </td>
                    <td>
                        &nbsp;</td>
    	        </tr>
                <tr>
                    <td><label>Categoria</label></td>
                    <td>
                        <asp:DropDownList runat="server" ID="cbCategoria"
                            ItemType="Box.Entities.Categoria"
                            SelectMethod="GetCategorias"
                            DataTextField="NombreCategoria"
                            DataValueField="Id" />
                    </td>
                    <td>Tipod de Producto</td>
                    <td>
                        <asp:DropDownList runat="server" ID="cbTipoProducto"
                            ItemType="Box.Entities.TipoProducto"
                            DataTextField="NombreTipoProducto"
                            DataValueField="Id"
                            SelectMethod="GetTipoProduto"/>
                    </td>
                </tr>
                <tr>
                    <td><label>Comentario</label></td>
                    <td><asp:TextBox runat="server" ID="txtComentario" MaxLength="255" CssClass="form-control input-sm" TextMode="MultiLine" /></td>
                    <td><label>Activo</label></td>
                    <td><asp:CheckBox runat="server" ID="txtEstado" Checked="True"/></td>
                </tr>
    	    </table>
            <br />


            
                    <div class="row">
                        <div class="col-md-6 .col-md-push-3">
                            <div class="panel panel-primary">
                                <div class="panel-heading">
                                    <h3>Productos</h3>
                                </div>
                                <div class="panel-body">
                             <table>
				                    <tr>
					            <td><label>Criterio:</label></td>
					            <td><asp:TextBox ID="txtCriterio" placeholder="Buscar" runat="server"/></td>
					            <td><asp:Button runat="server" CssClass="btn btn-primary btn-sm" Text="Buscar" ID="btnBuscar"/></td>
				                </tr>
				            </table>
                                    <asp:UpdatePanel runat="server" ID="upProductos">
                <ContentTemplate>
                    <asp:ListView runat="server" ID="lvInsumos" SelectMethod="GetInsumos"
                        ItemType="Box.Entities.Insumo" OnItemCommand="lvInsumos_ItemCommand">
                        <EmptyDataTemplate>
                            <b>No se han encontrado Insumos..!!</b>
                        </EmptyDataTemplate>
                        <LayoutTemplate>
                            <table class="table table-hover table-condensed">
                                <thead>
                                    <tr>
                                        <th>Nombre</th>
                                        <th>Stock</th>
                                        <th>Marca</th>
                                        <th>Precio</th>
                                        <th colspan="2">Acciones</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <tr id="itemPlaceholder" runat="server"/>
                                </tbody>
                            </table>
                             <asp:DataPager ID="dpProductos" PagedControlID="lvInsumos" runat="server" PageSize="5">
                             <Fields>
                             <asp:NextPreviousPagerField
                                                                ButtonType="Link"
                                                                ShowFirstPageButton="True"
                                                                ShowLastPageButton="True"
                                                                ShowNextPageButton="True"
                                                                ShowPreviousPageButton="True" />
                               </Fields>
                             </asp:DataPager>
                        </LayoutTemplate>
                        <ItemTemplate>
                            <tr>
                                <td><%# Item.NombreInsumo +" "+ Item.DescripcionInsumo  %></td>
                                <td><%# Item.Stock %></td>
                                <td><%# Item.Marca.NombreMarca %></td>
                                <td><%# Item.Precio %></td>
                                <td>
										<asp:Button ID="btnAgregar"
											Text="+" CommandName="AddDetalle"
											CommandArgument="<%# Item.Id %>"
											CssClass="btn btn-success" Width="35px" Height="35px" runat="server"/>										
                                </td>
                            </tr>
                        </ItemTemplate>
                    </asp:ListView>
                </ContentTemplate>
                <Triggers>
                    <asp:AsyncPostBackTrigger ControlID="btnBuscar" EventName="Click"/>                            
                </Triggers>
            </asp:UpdatePanel>
                                </div>
                                </div>
                            </div>

                        <div class="col-md-6 .col-md-push-3">
                            <div class="panel panel-primary">
                                <div class="panel-heading">
                                    <h3>Detalle </h3>
                                </div>
                                <div class="panel-body">

                                    <asp:UpdatePanel runat="server" ID="upDetlProducto">
                    <ContentTemplate>
                        <asp:ListView runat="server" ID="lvDetalleProducto" OnItemCommand="lvDetalleProducto_ItemCommand">
                            <EmptyDataTemplate>
                                <table class="table table-hover table-condensed">
                                    <thead>
                                        <tr>
                                            <th>Nombre</th>
                                            <th>Und. Medida</th>
                                            <th>Cantidad</th>
                                            <th>Precio</th>
                                            <th>Monto</th>
                                            <th>Acciones</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <b>No tiene insumos agregados a su detalle</b>
                                    </tbody>
                                    <tfoot>
                                        <tr>
                                            <td></td>
                                            <td></td>
                                            <td></td>
                                            <td></td>
                                            <td></td>
                                            <td></td>
                                            <td></td>
                                        </tr>
                                    </tfoot>
                                </table>
                            </EmptyDataTemplate>
                            <LayoutTemplate>
                                <table class="table table-hover table-condensed">
                                    <thead>
                                        <tr>
                                            <th>Nombre</th>                                                                                    
                                            <th>Und. Medida</th>
                                            <th>Cantidad</th>
                                            <th>Precio</th>
                                            <th>Monto</th>
                                            <th>Acciones</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <tr id="itemPlaceholder" runat="server"/>
                                    </tbody>
                                    <tfoot>
                                        <tr>
                                            <td>
												<%--<asp:Button runat="server"
													ID="btnActualizarDetalle"
													Text="Actualizar Detalle"
													CommandName="ActualizarDetalle" />--%>
											</td>
                                            <td></td>
                                            <td></td>
                                            <td></td>
                                            <td><h3><label>Total:</label></h3></td>
                                            <td><h2><asp:Label runat="server" ID="lblTotal"/></h2></td>
                                            <td></td>
                                        </tr>
                                    </tfoot>
                                </table>
                            </LayoutTemplate>
                            <ItemTemplate>
                                <tr>
                                    <td><%# Eval("Insumo.NombreInsumo") %></td>                                                                      
                                    <td><%# Eval("Insumo.MedidaInsumo") %></td>
                                    <td><asp:TextBox runat="server" ID="txtCantidad" AutoPostBack="False" OnTextChanged="txtCantidad_TextChanged" Text='<%# Bind("Cantidad") %>' Width="50px"/></td>
							        <td><asp:TextBox runat="server" ID="txtPrecio" AutoPostBack="False" OnTextChanged="txtPrecio_TextChanged" Text='<%# Bind("PrecioUnit") %>' Width="50px"/></td>                                    
                                    <td><%# Eval("Monto") %></td>
                                    <td>
										<asp:Button ID="btnQuitar" runat="server" Text="Quitar"
											CssClass="btn btn-danger btn-sm"
											CommandName="QuitarDetalle"
											CommandArgument='<%# Eval("IdInsumo") %>'/>
									</td>
                                </tr>
                            </ItemTemplate>
                        </asp:ListView>                        
                    </ContentTemplate>
                    <Triggers>
                        <asp:AsyncPostBackTrigger ControlID="lvInsumos" EventName="ItemCommand"/>
                        <asp:AsyncPostBackTrigger ControlID="lvDetalleProducto" EventName="ItemCommand"/>
                        <asp:AsyncPostBackTrigger ControlID="btnGuardar" EventName="Click"/>
                    </Triggers>
                </asp:UpdatePanel>
                                </div>
                                </div>
                            </div>

                   </div>

			<br/><br/>
          
            


                
    	    
    	</div>
    	<div class="panel-footer">
    	    <asp:Button runat="server" ID="btnGuardar" Text="Guardar" CssClass="btn btn-success" OnClick="btnGuardar_Click"/>
    	</div>
    </div>

</asp:Content>
